﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFIDA.U9.SCM.SM.SOUIModel;
using UFSoft.UBF.UI.WebControlAdapter;
using UFSoft.UBF.UI.ControlModel;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.Engine.Builder;
using System.Data;
using UFSoft.UBF.Util.DataAccess;
using UFSoft.UBF.Sys.Database;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.Association.Adapter;
using UFSoft.UBF.UI.WebControls.Association;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using System.Collections;
using System.Collections.Specialized;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.UI.WebControls;
using UFIDA.U9.UI.PDHelper;
using UFSoft.UBF.Business;
using UFSoft.UBF.View.Query;
using UFSoft.UBF.UI.IView;
using UFIDA.U9.FI.ER.LoanBillUIModel;
using UFIDA.U9.YD.Cli.PlugUI;
using UFIDA.U9.FI.ER.LoanPayingUIModel;
using UFIDA.U9.FI.ER.ReimburseBillUIModel;
using UFIDA.U9.YD.Cli.PlugUI.YD;

namespace UFIDA.U9.YD.Cli.PlugUI
{
    /// <summary>
    /// 报销单
    /// 控制 弃审/删除/审核 按钮不能点击
    /// </summary>
    public class YDReimburseBillUIFormWebPart : UFSoft.UBF.UI.Custom.ExtendedPartBase
    {
        private ReimburseBillMainUIFormWebPart part;
        IUFDataGrid DataGrid4;
        //配置文件XX.config文件拷贝到portal下，dll文件放置到portal/UILib下
        //配置文件以WebPartExtend开头
        public override void AfterInit(IPart Part, EventArgs args)
        {
            //首先调用原来的事件
            base.AfterInit(Part, args);
            part = Part as ReimburseBillMainUIFormWebPart;

            if (part == null)
                return;

        }

        public override void BeforeEventProcess(IPart Part, string eventName, object sender, EventArgs args, out bool executeDefault)
        {
            #region 在按钮点击前事件,添加判断逻辑
            try
            {
                //默认执行后续
                executeDefault = true;

                //获取参数 运达费控集成控制
                string pval = YDUtils.GetParam("YDFKJCKZ");
                string orgcode = PDContext.Current.OrgRef.CodeColumn;
                if (!pval.Contains(orgcode)) return;

                UFWebButton4ToolbarAdapter webButton = sender as UFWebButton4ToolbarAdapter;
                //webButton.ClientID就是界面控件的ID
                if (webButton != null 
                    && (webButton.ClientID == "u_M_p0_BtnDelete"
                    || webButton.ClientID == "u_M_p0_BtnApprove"
                    || webButton.ClientID == "u_M_p0_BtnUndoApprove"))
                {
                    throw new Exception($"不能手工执行该操作");

                    //string lyxt = this.part?.Model.ReimburseBillHead.FocusedRecord?.DescFlexField_PrivateDescSeg16;
                    //if (!string.IsNullOrEmpty(lyxt))
                    //{
                    //    throw new Exception($"来源系统[{lyxt}]单据,不能手工执行该操作");
                    //}
                }
            }
            catch (Exception ex)
            {
                ReimburseBillUIModelModel model = this.part.Model;
                UIPlugHelper.SetErrorMsg(model,model.ReimburseBillHead.FocusedRecord, null, ex.Message);
                executeDefault = false;//不再执行后续操作
                return;
            }
            #endregion
            base.BeforeEventProcess(Part, eventName, sender, args, out executeDefault);
        }




    }
}
